# 获取书城的内容
from flask import request, Blueprint

from api.decorators import cache
from api.slider import get_json_response, get_sort_more, server_exception, get_book_store

store_type = {
    -1: '5a03ffe1f958913a73b2ecd7',  # 精选
    0: '5a040027f958913a73b2ecda',  # 男频
    1: '5a040045f958913a73b2ecdb',  # 女频
    2: '5a04006cf958913a73b2ecdd',  # 出版
    3: '5a03fff0f958913a73b2ecd8',  # VIP封推
    4: '5a040000f958913a73b2ecd9',  # 免费
}

book_store = Blueprint('book_store', __name__)


@book_store.route('/bookstore')
@cache
def book_store_response():
    select = request.args.get('select', 0, int)
    size = request.args.get('size', 5, int)
    print(store_type.get(select))
    params = {
        'pl': 'ios',
        'sex': 'male',
        'size': size,
        'node': store_type.get(select)
    }
    content = get_book_store(params)
    return get_json_response(content, request)


# 获取列表信息
@book_store.route('/recommendPage')
@cache
def book_store_more_response():
    more = request.args.get('moreId', '', str)
    if more == '':
        return server_exception('more is null')
    content = get_sort_more(more)
    return get_json_response(content, request)
